#include "relievepage.h"
#include "ui_relievepage.h"

relievePage::relievePage(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::relievePage)
{
    ui->setupUi(this);
    ui->id->setText("账号");
    ui->psw->setText("密码");
    ui->checking->setText("验证");
    ui->tips->setText("");
    ui->record->setText("事件描述记录");
    ui->relieve->setText("确认解除");
    ui->widget_2->hide();
}

relievePage::~relievePage()
{
    delete ui;
}

void relievePage::on_checking_clicked()
{
    //验证是否为管理员
    if(DB.selecting(ui->lineEdit_id->text(),ui->lineEdit_psw->text()))
    {
        ui->widget1->hide();
        ui->widget_2->show();
        ui->tips->setText("");
        ui->lineEdit_id->setText("");
        ui->lineEdit_psw->setText("");
        ui->textEdit_record->setText("");
    }
    else
    {
        ui->tips->setText("验证错误");
    }

}
//重写窗口关闭事件  作用：清空之前输入的内容
void relievePage::closeEvent(QCloseEvent *e)
{
    ui->tips->setText("");
    ui->lineEdit_id->setText("");
    ui->lineEdit_psw->setText("");
    ui->textEdit_record->setText("");
    ui->widget_2->hide();
    ui->widget1->show();
}

//解除按钮
void relievePage::on_relieve_clicked()
{
    emit checkingSuccess();  //发送解除信号
    emit log(ui->textEdit_record->toPlainText());
    this->hide();  //关闭当前窗口

    //恢复默认
    ui->widget_2->hide();
    ui->widget1->show();
}

void relievePage::changPage(QString DotName, QString siteName, int errorType)
{
    QString type;
    switch (errorType)
    {
    case 0:
        type = "一级警报" ;break;
    case 1:
        type = "二级警报" ;break;
    case 2:
        type = "三级警报" ;break;
    }
    ui->label_error->setText(QString("在 %1 区域的 %2 站点 发生 %3").arg(DotName).arg(siteName).arg(type));
}
